import { createStore, applyMiddleware, combineReducers } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunkMiddleware from "redux-thunk";
import reducers from "./reducers";

// CREATING INITIAL STORE
export default function getStore(initialState) {
  const store = createStore(
    combineReducers(reducers),
    initialState,
    composeWithDevTools(applyMiddleware(thunkMiddleware))
  );

  // IF REDUCERS WERE CHANGED, RELOAD WITH INITIAL STATE
  // if (module.hot) {
  //   module.hot.accept("./reducers", () => {
  //     const createNextReducer = require("./reducers").default;

  //     store.replaceReducer(createNextReducer(initialState));
  //   });
  // }

  return store;
}
